
/*
 *  \file db_internal.h
 *
 *  Module internal header file for SDP Database
 */

/*
 *  Copyright (C) 2013. Mindtree Ltd.
 *  All rights reserved.
 */

#ifndef _H_DB_INTERNAL_
#define _H_DB_INTERNAL_

/* ------------------------ Header File Inclusion */
#include "database.h"


/* ------------------------ Structure Declarations Section */


/* ------------------------ Macros */
#define db_memset    BT_mem_set
#define db_memcmp    BT_mem_cmp
#define db_alloc     BT_alloc_mem
#define db_free      BT_free_mem

/* Macros for Debug */
#ifndef DB_NO_DEBUG
#define DB_ERR(...)       BT_debug_error(BT_MODULE_ID_DB, __VA_ARGS__)
#else  /* DB_NO_DEBUG */
#define DB_ERR            BT_debug_null
#endif /* DB_NO_DEBUG */

#ifdef DB_DEBUG

    #define DB_TRC(...)   BT_debug_trace(BT_MODULE_ID_DB, __VA_ARGS__)
    #define DB_INF(...)   BT_debug_info(BT_MODULE_ID_DB, __VA_ARGS__)

#else /* DB_DEBUG */

    #define DB_TRC        BT_debug_null
    #define DB_INF        BT_debug_null

#endif /* DB_DEBUG_ELSE */

/* Base SDDB Record Handle */
#define SDDB_BASE_RECORD_HANDLE 0x00090000

/** Lock the DB SDP global mutex */
#define DB_SDP_LOCK()        BT_MUTEX_LOCK(db_sdp_mutex, DB)

/** Unlock the DB SDP global mutex */
#define DB_SDP_UNLOCK()      BT_MUTEX_UNLOCK(db_sdp_mutex, DB)

/** Validate SDDB Record Handle */
#define SDDB_VALIDATE_RECORD_HANDLE(record_handle, offset) \
    if((SDP_SERVER_RECORD_HANDLE != (record_handle)) && \
       ((SDDB_BASE_RECORD_HANDLE == (record_handle)) || \
       (((record_handle) & SDDB_BASE_RECORD_HANDLE)!=SDDB_BASE_RECORD_HANDLE)\
       ||((offset) >= num_records)))\
    { \
        DB_ERR( \
        "Record Handle (0x%08X) not present in SDDB\n", \
        (unsigned int)record_handle);\
         \
        return DB_RECORD_HANDLE_NOT_FOUND; \
    }

/* ------------------------- DB SDP interface Utility Functions */
/*
 *  This function searches if uuid search indices
 *  are present in an SDDB record
 */
UINT32 db_sdp_match_uuid_list
       (
           /* IN */ UCHAR *search,
           /* IN */ UINT16 search_count,
           /* IN */ UCHAR *from,
           /* IN */ UINT16 list_count
       );

#endif /* _H_DB_INTERNAL_ */

